package dome1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 泛型代码测试
 * User: 王圆豪
 * Date: 2024-07-08
 * Time: 20:39
 */

class MyArray<E>{
    private Object[] po = new Object[10];

    public E getPo(int pos) {
        return (E)po[pos];
    }

    public void setPo(int pos, E po) {
        this.po[pos] = po;
    }

    @Override
    public String toString() {
        return "MyArray{" +
                "po=" + Arrays.toString(po) +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setPo(0, 1);
//        myArray.setPo(1, "hello");//自动检查存放的数据类型
        System.out.println(myArray);
        Integer a = myArray.getPo(0);
        System.out.println(a);

//        MyArray myArray = new MyArray();
//        myArray.setPo(0, 1);
//        myArray.setPo(1, "hello");
//        System.out.println(myArray);
//        String s = (String) myArray.getPo(1);
//        System.out.println(s);
    }
}
